﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.IO.IsolatedStorage;
using Microsoft.Phone.Tasks;


namespace WindowsPhoneApplication1
{
    public partial class addComPicPage : PhoneApplicationPage
    {

        String comment;
        String name;
        BitmapImage picture;

        IsolatedStorageSettings trkCom = IsolatedStorageSettings.ApplicationSettings;
        

        public addComPicPage()
        {
            InitializeComponent();
        }

        private void addCom_GotFocus(object sender, RoutedEventArgs e)
        {
            if (addCom.Text == "Add your comment here")
                addCom.Text = "";

        }

        private void addCom_LostFocus(object sender, RoutedEventArgs e)
        {
            if (addCom.Text == String.Empty)
            {
                SolidColorBrush Brush2 = new SolidColorBrush();
                Brush2.Color = Colors.Black;
                addCom.Foreground = Brush2;
                addCom.Text = "Add your comment here";
            }

            else
            {
                SolidColorBrush Brush2 = new SolidColorBrush();
                Brush2.Color = Colors.Blue;
                addCom.Foreground = Brush2;
                comment = addCom.Text;
            }

        }

        private void addButton_Click(object sender, RoutedEventArgs e)
        {
            if (!trkCom.Contains("comment"))
                trkCom.Add("comment", addCom.Text);
            else
                trkCom["comment"] = addCom.Text;

            if (!trkCom.Contains("username"))
                trkCom.Add("username", addName.Text);
            else
                trkCom["username"] = addName.Text;

            trkCom.Save();

            Microsoft.Phone.Shell.PhoneApplicationService.Current.State["pic"] = picture;

            NavigationService.Navigate(new Uri("/commentPage.xaml" , UriKind.RelativeOrAbsolute));
 
        }

        private void addName_LostFocus(object sender, RoutedEventArgs e)
        {
            if (addName.Text == String.Empty)
            {
                SolidColorBrush Brush2 = new SolidColorBrush();
                Brush2.Color = Colors.Black;
                addName.Foreground = Brush2;
                addName.Text = "Add your name here";
            }

            else
            {
                SolidColorBrush Brush2 = new SolidColorBrush();
                Brush2.Color = Colors.Blue;
                addName.Foreground = Brush2;
                name = addName.Text;
            }
        }

        private void addName_GotFocus(object sender, RoutedEventArgs e)
        {
            if (addName.Text == "Add your name here")
                addName.Text = "";
        }

        private void browseButton_Click(object sender, RoutedEventArgs e)
        {
            PhotoChooserTask photoChooserTask = new PhotoChooserTask();
            photoChooserTask.Completed += new EventHandler<PhotoResult>(photoChooserTask_Completed);
            photoChooserTask.Show();
        }

        void photoChooserTask_Completed(object sender, PhotoResult e)
        {
            if (e.TaskResult == TaskResult.OK)
            {
                picture = new BitmapImage();
                picture.SetSource(e.ChosenPhoto);
            }

        }
        
    }

}